package com.agua.enturno.vista.modelos;

import org.apache.wicket.model.IModel;
import org.joda.time.DateTime;
import org.joda.time.LocalTime;


public class TimeModel implements IModel<String> {
	
	private static final long serialVersionUID = 1L;
	
	private IModel<DateTime> dateTimeModel;
	
	public TimeModel(IModel<DateTime> dateTimeModel) {
		this.dateTimeModel = dateTimeModel;
	}

	@Override
	public void detach() {
		dateTimeModel.detach();
	}

	@Override
	public String getObject() {
		return dateTimeModel.getObject().toLocalTime().toString();
	}

	@Override
	public void setObject(String object) {
		
		LocalTime localTime = LocalTime.parse(object);
		this.dateTimeModel.setObject(this.dateTimeModel.getObject().withTime(localTime.getHourOfDay(), localTime.getMinuteOfHour(), 0, 0));
	}
	
}
